package com.md.sockettest.socketv1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

/**
 * @Author Gong
 * @Description
 * @dATE 2022/3/30 15:34
 **/
public class SocketTest {
    public static void main(String[] args) throws IOException {
        //创建Socket，指定ip，port
        Socket socket = new Socket("127.0.0.1", 8080);

        //获得基于Socket的输入流和输出流
        PrintWriter os = new PrintWriter(socket.getOutputStream());//发给服务器的数据
//        BufferedReader is = new BufferedReader(new InputStreamReader(
//                socket.getInputStream()));

        //独立的接收服务端数据的线程
        ClientThread ct = new ClientThread(socket);
        ct.start();//接收服务器的信息的线程
        //向服务器写数据


        //获得键盘输入
        BufferedReader sin = new BufferedReader(new InputStreamReader(
                System.in));
        String readline;
        while (!(readline=sin.readLine()).equals("exit")) {
            os.println(readline);
            os.flush();//发给了服务器
        }

    }
}
